package xyz.lxx.springboottest.Aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * ClassName:aopTest
 * Package:xyz.lxx.springboottest.Aspectj
 * Description:
 *
 * @Date:2020/9/23 19:20
 * @Author:857251389@qq.com
 */

@Aspect
@Component
public class aopTest {


    @Pointcut("execution(* xyz.lxx.springboottest.service.*.*(..))")
    public void pointcut(){

    }

    @Before("pointcut()")
    public void before(){

        System.out.println("前置通知");
    }

    @After("pointcut()")
    public void after(){

        System.out.println("after");
    }

    @AfterReturning(value = "pointcut()",returning = "returnObject")
    public void afterReturning(JoinPoint joinPoint, Object returnObject){

        System.out.println("AfterReturning");
    }

    @AfterThrowing("pointcut()")
    public void afterThrowing(){
        System.out.println("afterThrowing");
    }


    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable    {

        try {
            System.out.println("around");
            return joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        } finally {
            System.out.println("around");
        }
    }
}
